#!/usr/bin/env python
#-*- coding:utf-8 -*-
# author:Vergil
# datetime:2018/12/14 16:55
from django import forms
from .models import User, Certification


class LoginForm(forms.Form):
    """
    登录表单
    """
    username = forms.CharField(label='昵称', max_length=254, required=True, widget=forms.TextInput(attrs={'autofocus': ''}))
    password = forms.CharField(label='密码', max_length=128, widget=forms.TextInput(attrs={'type': 'password'}))


class RegisterForm(forms.Form):
    """
    注册表单
    """
    username = forms.CharField(label='昵称', max_length=20)
    pwd = forms.CharField(label='密码', widget=forms.PasswordInput())
    pwd_again = forms.CharField(label='确认密码', widget=forms.PasswordInput())
    sex = forms.ChoiceField(label='性别', choices=((0, '男'), (1, '女'),), initial=0, widget=forms.Select)
    age = forms.CharField(label='年龄', max_length=3)
    phone_number = forms.CharField(label='联系方式', max_length=11)
    email = forms.EmailField(label='电子邮箱')


class EditForm(forms.ModelForm):
    """
    个人信息修改表单
    """
    username = forms.CharField(label='昵称', max_length=30, widget=forms.TextInput(attrs={'class': 'form-control rounded input-lg'}))
    sex = forms.ChoiceField(label='性别', choices=((0, '男'), (1, '女'),), initial=0, widget=forms.Select(attrs={'class': 'form-control rounded input-lg'}))
    age = forms.CharField(label='年龄', max_length=3, widget=forms.TextInput(attrs={'class': 'form-control rounded input-lg'}))
    phone_number = forms.CharField(label='联系方式', max_length=11, widget=forms.TextInput(attrs={'class': 'form-control rounded input-lg'}))
    email = forms.EmailField(label='电子邮箱', widget=forms.TextInput(attrs={'class': 'form-control rounded input-lg'}))
    summary = forms.CharField(label='个人简介', widget=forms.TextInput(attrs={'class': 'form-control rounded input-lg'}))
    avatar = forms.ImageField(label='头像', widget=forms.FileInput(attrs={'class': 'form-control rounded input-lg'}))

    class Meta:
        model = User
        fields = ('username', 'age', 'sex', 'phone_number', 'email', 'summary', 'avatar', )


class CertificationForm(forms.ModelForm):
    """
    实名认证表单
    """
    user = forms.CharField(label='用户', max_length=128, required=False, widget=forms.HiddenInput)
    real_name = forms.CharField(label='真实姓名', required=False, widget=forms.TextInput(attrs={'class': 'form-control rounded input-lg'}))
    id_card = forms.CharField(label='证件号码', required=False, widget=forms.TextInput(attrs={'class': 'form-control rounded input-lg'}))
    id_card_positive = forms.ImageField(label='身份证正面', required=False, widget=forms.FileInput(attrs={'class': 'form-control rounded input-lg'}))
    id_card_back = forms.ImageField(label='身份证背面', required=False, widget=forms.FileInput(attrs={'class': 'form-control rounded input-lg'}))

    class Meta:
        model = Certification
        fields = ('real_name', 'id_card', 'id_card_positive', 'id_card_back',)
